<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>品优购，优质！优质！-商品详情</title>
    <link rel="stylesheet" type="text/css" href="../static/css/reset.css">
    <link rel="stylesheet" type="text/css" href="../static/css/main.css">

</head>
<body>
<div class="header_con">
    <div class="header">
        <div class="welcome fl">欢迎来到品优购生鲜!</div>
        <div class="fr">
            <div class="login_info fl">
                欢迎您：<em>张 山</em>
            </div>
            <div class="login_btn fl">
                <a href="login.html">登录</a>
                <span>|</span>
                <a href="register.html">注册</a>
            </div>
            <div class="user_link fl">
                <span>|</span>
                <a href="user_center_info.html">用户中心</a>
                <span>|</span>
                <a href="/user/showCart">我的购物车</a>
                <span>|</span>
                <a href="user_center_order.html">我的订单</a>
            </div>
        </div>
    </div>
</div>

<div class="search_bar clearfix">
    <a href="index.html" class="logo fl"><img src="../static/images/logo.png"></a>
    <div class="search_con fl">
        <input type="text" class="input_text fl" name="" placeholder="搜索商品">
        <input type="button" class="input_btn fr" name="" value="搜索">
    </div>
    <div class="guest_cart fr">
        <a href="/user/showCart" class="cart_name fl">我的购物车</a>
        <div class="goods_count fl" id="show_count">1</div>
    </div>
</div>

<div class="navbar_con">
    <div class="navbar clearfix">
        <div class="subnav_con fl">
            <h1>全部商品分类</h1>
            <span></span>
            <ul class="subnav">
                <li><a href="#" class="fruit">新鲜水果</a></li>
                <li><a href="#" class="seafood">海鲜水产</a></li>
                <li><a href="#" class="meet">猪牛羊肉</a></li>
                <li><a href="#" class="egg">禽类蛋品</a></li>
                <li><a href="#" class="vegetables">新鲜蔬菜</a></li>
                <li><a href="#" class="ice">速冻食品</a></li>
            </ul>
        </div>
        <ul class="navlist fl">
            <li><a href="">首页</a></li>
            <li class="interval">|</li>
            <li><a href="">手机生鲜</a></li>
            <li class="interval">|</li>
            <li><a href="">抽奖</a></li>
        </ul>
    </div>
</div>

<div class="breadcrumb">
    <a href="#">全部分类</a>
    <span>></span>
    <a href="#">新鲜水果</a>
    <span>></span>
    <a href="#">商品详情</a>
</div>

<div class="goods_detail_con clearfix">
    <div class="goods_detail_pic fl"><img src="http://192.168.11.77:8888/{{.goodsSKU.Image}}"></div>

    <div class="goods_detail_list fr">
        <h3>{{.goodsSKU.Name}}</h3>
        <p>{{.goodsSKU.Desc}}</p>
        <div class="prize_bar">
            <span class="show_pirze">¥<em>{{.goodsSKU.Price}}</em></span>
            <span class="show_unit">单  位：{{.goodsSKU.Unite}}</span>
        </div>
        <div class="goods_num clearfix">
            <div class="num_name fl">数 量：</div>
            <div class="num_add fl">
                <input type="text" class="num_show fl" value="1" goodsId="{{.goodsSKU.Id}}">
                <a href="javascript:;" class="add fr">+</a>
                <a href="javascript:;" class="minus fr">-</a>
            </div>
        </div>
        <div class="total">总价：<em>16.80元</em></div>
        <div class="operate_btn">
            <a href="javascript:;" class="buy_btn">立即购买</a>
            <a href="javascript:;" class="add_cart" id="add_cart">加入购物车</a>
        </div>
    </div>
</div>

<div class="main_wrap clearfix">
    <div class="l_wrap fl clearfix">
        <div class="new_goods">
            <h3>新品推荐</h3>
            <ul>
            {{range .newGoods}}
                <li>
                    <a href="/goodsDetail?id={{.Id}}"><img src="http://192.168.11.77:8888/{{.Image}}"></a>
                    <h4><a href="/goodsDetail?id={{.Id}}">{{.Name}}</a></h4>
                    <div class="prize">￥{{.Price}}</div>
                </li>
            {{end}}
            </ul>
        </div>
    </div>

    <div class="r_wrap fr clearfix">
        <ul class="detail_tab clearfix">
            <li class="active">商品介绍</li>
            <li>评论</li>
        </ul>

        <div class="tab_content">
            <dl>
                <dt>商品详情：</dt>
                <dd>{{.goodsSKU.Goods.Detail}}</dd>
            </dl>
        </div>
    </div>
</div>

<div class="py-container copyright footer">
    <ul>
        <li>关于我们</li>
        <li>联系我们</li>
        <li>联系客服</li>
        <li>商家入驻</li>
        <li>营销中心</li>
        <li>手机品优购</li>
        <li>销售联盟</li>
        <li>品优购社区</li>
    </ul>
    <div class="address">地址：北京市昌平区建材城西路金燕龙办公楼一层 邮编：100096 电话：400-618-4000 传真：010-82935100</div>
    <div class="beian">京ICP备08001421号京公网安备110108007702
    </div>
</div>
<div class="add_jump"></div>

<script type="text/javascript" src="../static/js/jquery-1.12.4.min.js"></script>
<script type="text/javascript">
    var $add_x = $('#add_cart').offset().top;
    var $add_y = $('#add_cart').offset().left;

    var $to_x = $('#show_count').offset().top;
    var $to_y = $('#show_count').offset().left;

    $(".add_jump").css({'left': $add_y + 80, 'top': $add_x + 10, 'display': 'block'})
    //购物车点击添加事件
    $('#add_cart').click(function () {
        //添加到购物车,使用ajax发送post请求到后台
        //获取自定义属性用attr,获取原有属性用prop
        goodsId = $(".num_show").attr("goodsId")
        num = $(".num_show").val()
        //自定义json参数
        param = {"goodsId": goodsId, "num": num}
        $.post("/addCart", param, function (data) {
            if (data.errno != 5) {
                alert(data.errmsg)
            }
        })

        $(".add_jump").stop().animate({
                    'left': $to_y + 7,
                    'top': $to_x + 7
                    },
                    "fast", function () {
                    $(".add_jump").fadeOut('fast', function () {
                        $('#show_count').html(num);
                    });
        });
    })

    //点击标签添加商品数量
    $(".add").click(function () {
        //显示的数量加1
        num = $(".num_show").val()
        num = parseInt(num) + 1
        $(".num_show").val(num)

        //每加一次数量,都调用函数,计算总价
        CalcTotalPrice()
    });

    //定义函数,计算商品总价,总价 = 单价*数量
    function CalcTotalPrice() {
        //获取单价,获取input的值用value,获取非input的值用text
        price = $(".show_pirze").children("em").text();
        price = parseFloat(price)
        //数量
        count = $(".num_show").val()
        //计算总价
        totalPrice = price * parseInt(count)
        $(".total").children("em").text(totalPrice.toFixed(2) + "元")
    }

    //调用函数,计算总价
    CalcTotalPrice()

    //点击标签减少商品数量
    $(".minus").click(function () {
        //显示的数量减1
        //获取原来的数量
        num = $(".num_show").val()
        num = parseInt(num) - 1
        //判断num范围
        if (num <= 1) {
            num = 1
        }
        //赋值
        $(".num_show").val(num)

        //每减一次数量,都调用函数,计算总价
        CalcTotalPrice()
    });

    //手动输入商品数量
    $(".num_show").blur(function () {
        //对输入的值做校验,判断是否是数字,是否都是空格,值是否小于0
        num = $(this).val()
        if (isNaN(num) || num.trim().length == 0 || parseInt(num) <= 0) {
            num = 1
            $(this).val(num)
        }
        //修改总价
        CalcTotalPrice()
    });
</script>

</body>
</html>